home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / 3DGPL 1.0 / CODE / HARDWARE / 386-WAT / HARDWARE.C next >
Encoding:
C/C++ Source or Header  |  1995-06-20  |  3.9 KB  |  118 lines  |  [TEXT/MACA]

  1. /** 3DGPL *************************************************\
  2.  *  (MSDOS, i386+, VGA, WATCOM C)                         *
  3.  *  Header for hardware specific stuff.                   *
  4.  *                                                        *
  5.  *  Defines:                                              *
  6.  *    HW_open_screen         opening output surface;      *
  7.  *    HW_blit                colourmap onto the screen;   *
  8.  *    HW_close_screen        closing output;              *
  9.  *                                                        *
  10.  *    HW_run_event_loop      runiing for events;          *
  11.  *    HW_quit_event_loop     quiting running.             *
  12.  *                                                        *
  13.  *  (6/1995) By Sergei Savhenko. (savs@cs.mcgill.ca).     *
  14.  *  Copyright (c) 1995 Sergei Savchenko.                  *
  15.  *  THIS SOURCE CODE CAN'T BE USED FOR COMERCIAL PURPOSES *
  16.  *  WITHOUT AUTHORISATION                                 *
  17. \**********************************************************/
  18.  
  19. #include <conio.h>                          /* kbhit() etc. */
  20. #include "../hardware/hardware.h"           /* all the defenitions */
  21.  
  22. unsigned char *HW_colourmap;                /* where drawing are */
  23. int HW_running;                             /* event loop running? */
  24.  
  25. /**********************************************************\
  26.  *  Opening output surface and setting the palette.       *
  27.  *                                                        *
  28.  *  RETURNS: always 1.                                    *
  29.  *  --------                                              *
  30. \**********************************************************/
  31.  
  32. void HW_set_mode(void);
  33. #pragma aux HW_set_mode=   \
  34.  "mov  al,13h "            \
  35.  "xor  ah,ah"              \
  36.  "int  10h"                \
  37.  modify [ax];
  38.  
  39. void HW_set_colour(int r,int g,int b,int number);
  40. #pragma aux HW_set_colour= \
  41.  "mov  ax,1010h"           \
  42.  "int  10h"                \ 
  43.  parm  [dh] [ch] [cl] [bx];
  44.  
  45. int HW_open_screen(char *display_name,
  46.                    char *screen_name,
  47.                    struct HW_colour palette[256],
  48.                    unsigned char *colourmap
  49.                   )
  50. {
  51.  int i;
  52.  unsigned char r,g,b;
  53.  
  54.  HW_colourmap=colourmap;                    /* the graphics buffer */
  55.  
  56.  HW_set_mode();                             /* mode 13 */
  57.  
  58.  for(i=0;i<256;i++)
  59.  {
  60.   r=(unsigned char)palette[i].hw_r;
  61.   g=(unsigned char)palette[i].hw_g;
  62.   b=(unsigned char)palette[i].hw_b;
  63.   HW_set_colour(r,g,b,i);                   /* palette */
  64.  }
  65.  return(1);
  66. }
  67.  
  68. /**********************************************************\
  69.  *  Colormap onto the screen.                             *
  70. \**********************************************************/
  71.  
  72. void HW_blit(void)
  73. {
  74.  HW_copy_int((int*)HW_colourmap,(int*)0xa0000,HW_COLOURMAP_SIZE_INT);
  75. }
  76.  
  77. /**********************************************************\
  78.  *  Closing output surface.                               *
  79. \**********************************************************/
  80.  
  81. void HW_close_screen(void)
  82. {
  83. }
  84.  
  85. /**********************************************************\
  86.  *  Running the event loop.                               *
  87. \**********************************************************/
  88.  
  89. void HW_run_event_loop(void (*application_main)(void),
  90.                        void (*application_key_handler)(int key_code)
  91.                       )
  92. {
  93.  char c;
  94.  HW_running=1;
  95.  
  96.  while(HW_running==1)                       /* still running? hmmm */
  97.  {
  98.   if(kbhit()) 
  99.   {
  100.    c=getch();
  101.    if(c==0) application_key_handler(getch());
  102.    else application_key_handler(c);
  103.   }
  104.   application_main();
  105.  }
  106. }
  107.  
  108. /**********************************************************\
  109.  *  Stoping the event loop.                               *
  110. \**********************************************************/
  111.  
  112. void HW_quit_event_loop(void)
  113. {
  114.  HW_running=0;                              /* that's it */
  115. }
  116.  
  117. /**********************************************************/
  118.